package com.example.jetpackcomposestate.examples

import androidx.compose.foundation.layout.Column
import androidx.compose.material3.LocalContentColor
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.platform.LocalContext
import com.example.jetpackcomposestate.R

/**
 * @author huangzehui
 * @date 6/5/2024 下午10:20 周一
 * @description
 *
 * https://www.bilibili.com/video/BV1ob4y1a7ad?p=45&spm_id_from=pageDriver&vd_source=e07cc8cc94eb22bd76722071b03cd199
 *
 */

@Composable
fun CompositionSample2() {
    MaterialTheme {
        Column {
            Text(text = "kjskdjfksjdkjfksjdfkjskdjfkjskdjfkjskdjf")
            CompositionLocalProvider(LocalContentColor.provides(LocalContentColor.current.copy(alpha = 0.65f))) {
                Text(text = "kjskdjfksjdkjfksjdfkjskdjfkjskdjfkjskdjf")
                Text(text = "kjskdjfksjdkjfksjdfkjskdjfkjskdjfkjskdjf")
            }
            CompositionLocalProvider(LocalContentColor.provides(LocalContentColor.current.copy(alpha = 0.38f))) {
                DescendantExample()
            }

            FruitText(4)
        }
    }
}

@Composable
fun DescendantExample() {
    Text(text = "kjsdkjfksjdkfjksjdkfjskdjfkjskdjfjskdf")
}

@Composable
fun FruitText(fruitSize: Int) {
    val resources = LocalContext.current.resources
    val fruitText = resources.getQuantityString(R.plurals.fruit_title, fruitSize)
    Text(text = "$fruitSize $fruitText")
}
